<!DOCTYPE HTML>
<html>
  <head>
    <script type="text/javascript">
      function add_event( data )
      {
         var li = document.createElement( "li" );
         li.appendChild( document.createTextNode( "> " + data ) );

         var ul = document.getElementById( "events" );
         ul.appendChild( li );
      }

	  if ( !!window.EventSource )
	  {
	     var source = new EventSource( "http://localhost:1984/stream" );

         source.addEventListener( "message", function( evt )
         {
         	add_event( evt.data );
         }, false );

		 source.addEventListener( "open", function( evt )
		 {
		    add_event( "EventSource open." );
		 }, false );

         source.addEventListener( 'error', function( evt )
         {
            if ( evt.readyState == EventSource.CLOSED )
            {
               add_event( "EventSource closed." );
            }
         }, false );
	  }
	  else
	  {
	    alert( "WebSockets NOT supported by your Browser!" );
	  }
    </script>
  </head>
  <body>
  	<h1>Incoming Events</h1>
  	<ul id="events">
  	</ul>
  </body>
</html>
